package br.requisiteworks.util.validacao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

public final class TradutorErros {
	private TradutorErros(){}
	
	public static Map<String, String> traduz(ConstraintViolationException exception){
		Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
		Map<String, String> map = new HashMap<String, String>(constraintViolations.size());
		
		Iterator<ConstraintViolation<?>> iterator = constraintViolations.iterator();
		
		while(iterator.hasNext()){
			ConstraintViolation<?> next = iterator.next();
			
			map.put(next.getPropertyPath().toString(), next.getMessage());
		}
		
		return map;
	}
}
